def solve(intervals):
    intervals.sort(key=lambda x:x[0])
    #print(intervals)
    ans=[intervals[0]]
    for i in range(1,len(intervals)):
        a1,b1,a2,b2=ans[-1][0],ans[-1][1],intervals[i][0],intervals[i][1]
        if b1<a2: ans.append(intervals[i])
        else: 
            ans.pop()
            ans.append([a1,max(b1,b2)])
    return ans 

intervals=[]
while True:
    tmp=[int(i) for i in input().split()]
    if len(tmp)==2: intervals.append(tmp)
    else: break 
#intervals = [[1,3],[2,6],[8,10],[15,18]]
print(solve(intervals))

